package com.test;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.test.entity.Score;
import com.test.entity.UserScore;
import com.test.mapper.aa.ActivityMapper;
import com.test.mapper.aa.ScoreMapper;
import com.test.mapper.aa.UserMapper;
import com.test.mapper.aa.UserScoreMapper;
import com.test.mapper.bb.ChannelUserMapper;

import tk.mybatis.mapper.entity.Example;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = MiniApp.class)
public class SpringBootTestExample {
	
	
	@Resource
	private ActivityMapper activityMapper ;
	
	@Resource
	private UserMapper userMapper ;
	
	@Resource
	private ScoreMapper  scoreMapper ;
	
	@Resource
	private UserScoreMapper userScoreMapper ;
	
	@Resource
	private ChannelUserMapper channelUserMapper ;
	
	
	@Test
	public void testTkPage7() {
		
		try{
			//com.test.mapper.aa.UserScoreMapper 
		    System.err.println("---------------------------------------------");
			
			System.err.println("---------------------------------------------");
			
			System.out.println(channelUserMapper.selectAll());
			System.out.println(channelUserMapper.countChannels());
			
			System.err.println("---------------------------------------------");
		}catch(Exception e){
			e.printStackTrace(); 
		}
		
	}
	
	
	@Test
	public void testTkPage6() {
		
		try{
			//com.test.mapper.aa.UserScoreMapper 
		    System.err.println("---------------------------------------------");
			PageHelper.startPage(2, 5 );  
		    UserScore userScore = new UserScore() ;
			List<UserScore> list = userScoreMapper.selectUserScore(userScore) ;
			PageInfo<UserScore> pageInfo = new PageInfo<>(list);
			System.out.println(JSON.toJSONString(pageInfo));
			System.err.println("---------------------------------------------");
			
			System.out.println(userScoreMapper.selectMaxScore());
			
			System.err.println("---------------------------------------------");
		}catch(Exception e){
			e.printStackTrace(); 
		}
		
	}

	@Test
	public void testTkUserMapper3() {
		
		try{
			System.err.println("---------------------------------------------");
			Score score1 = new Score() ;
			score1.setFreezeScore(0);
			score1.setEffectScore(0);
			score1.setTotalScore(0);
			score1.setEffectScore(0);
			score1.setInserttime(new Date());
			score1.setUserCode("test0001");
			
			scoreMapper.insert(score1) ;
			System.out.println(JSON.toJSONString(score1));
			
			score1.setUpdatetime(new Date());
			scoreMapper.updateByPrimaryKey(score1) ;
			
			Example example = new Example(Score.class) ;
			example.createCriteria().andEqualTo("userCode" , "1596853439774720") ;
			scoreMapper.updateByExample(score1, example) ;
			
			
			System.err.println("---------------------------------------------");
		}catch(Exception e){
			e.printStackTrace(); 
		}
		
	}
}
